<?php

/*
 * Author: thanhvd
 * Mail  : thanhvd89@gmail.com
 * Blog  : thanhvd89.wordpress.com
 * 
 */

session_start();

function __autoload($classname) {
    $classname = strtolower($classname);
    $arr = explode("_", $classname);
    
    $file_path = BASE_DIR."protected/controllers/".$classname.".php";
    if (count($arr) == 2 && $arr[1] == "model") $file_path = BASE_DIR."protected/models/".$classname.".php";
    
    if (file_exists($file_path))
        require_once $file_path;
    else
        throw new Exception("Class not found!");
}

function autoload_core_files() {
    $core_files = glob(BASE_DIR."core/*.php");
    foreach ($core_files as $file) require_once $file;
}

function autoload_library_files() {    
    require_once BASE_DIR."libraries/adodb5/adodb.inc.php";
    require_once BASE_DIR."libraries/xtemplate/xtemplate.class.php";
}

function autoload_config_file() {
    require_once BASE_DIR."config/config.php";
}

autoload_library_files();
autoload_config_file();
autoload_core_files();


?>
